package com.example.jinzproduct.controller;

import com.example.commons.entity.UserDO;
import com.example.commons.entity.UserRoleDO;
import com.example.commons.utils.ApiEnumError;
import com.example.commons.utils.ApiResult;
import com.example.commons.utils.JWTUtil;
import com.example.jinzproduct.oss.OssService;
import com.example.jinzproduct.server.UserRoleService;
import com.example.jinzproduct.server.UserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.java.Log;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author mengzhichao
 * @create 2022-08-30-9:28
 */
@RestController
@RequestMapping("/jinZhiIndex/Oss")
public class OssController {

    @Autowired
    OssService ossService;

    @Autowired
    UserService userService;


    /**
     * api小程序端-文件上传接口
     */
    @PostMapping("/fileImprot")
    @Transactional
    public ApiResult<?> fileImprot(@RequestParam("file") MultipartFile file) {
        String url = "";
        url = ossService.uploadFileOss2(file);
        System.out.println("分片上传视频地址++++++++++++++++++++++++++++++++++++++++++"+url);
        return ApiResult.success("上传成功", url);
    }


//    /**
//     * 头像上传
//     * @param file
//     * @param avatar_data
//     * @param request
//     * @return
//     * @throws Exception
//     */
//    @ResponseBody
//    @PostMapping("/uploadImg")
//    ApiResult<?> uploadImg(@RequestParam("avatar_file") MultipartFile file, String avatar_data, HttpServletRequest request)
//            throws Exception {
////        UserDO user = JWTUtil.getUser();
//        UserDO user =new UserDO();
//        user.setId(1509349086594027522L);
//        Map<String, Object> result = new HashMap<>();
//        result = userService.updatePersonalImg(file, avatar_data, user.getId());
//        return ApiResult.success(result);
//    }
//

}
